//
// Created by ZLY on 2025/5/13.
//

#include "timer.h"

Timer * Timer::addTimerChild(Object *parent, float interval) {
    auto timer = new Timer();
    timer->setInterval(interval);
    if (parent) {
        parent->addChild(timer);
    }
    timer->setActive(false);
    return timer;
}

void Timer::update(float dt) {
    Object::update(dt);
    timer_+=dt;
    if (timer_>=timer_interval_) {
        timer_=0;
        time_out_=true;
    }
}

bool Timer::timeOut() {
    if (time_out_) {
        time_out_ = false;
        return true;
    }
    return false;
}
